<template lang="html">
  <div class="main-page" id="store-page">
    <!-- 主体内容 -->
    <!-- <van-nav-bar class="main-header" title="新手专享" :left-arrow="true" :fixed="true" :z-index="11" @click-left="onClickLeft" /> -->
    <nav-bar :title="'新人专享'"  @goBack="onClickLeft"/>

    <div class="main-content has-header-space">
      <!--pages/pact/gvrp/gvrp.wxml-->
      <div class="exclusive_page">
        <div class="banner">
          <img src="https://mjmh.meijiameihuo.com/wechat/images/v2/exce_new_bg.png" />
        </div>
        <div class="prd_list">
          <van-list v-model="loading" error-text="请求失败，点击重新加载" @load="onLoad()" loading-text="正在加载中" :finished="finished">
            <Item :itemtype="type" v-for="(item, key) in prd_list" :item="item" v-bind:key="key" :user_info="user_info"></Item>
          </van-list>
          <!-- <div class="nodata" v-if="!prd_list.length && !loading"> -->
            <!-- <nodata txt="暂无数据" height="calc(100vh - 550rpx)"></nodata> -->
          <!-- </div> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Item from '@/components/active/exclusive/new_item.vue'
import NavBar from '@/components/global/nav-bar.vue'

export default {
  components: { Item, NavBar },
  data () {
    return {
      prd_list: [],
      backgroundcolor: '',
      backgroundimage: '',
      type: 'new',
      page: 0,
      finished: false,
      loading: true,
      show: true,
      user_info: {}
    }
  },
  created () {
    this.getProfile()
    this.getList()
  },
  methods: {
    onClickLeft () {
      this.$router.go(-1)
    },
    onLoad () {
      this.page = this.page + 1
      this.getList()
    },
    getProfile () {
      return new Promise((resolve, reject) => {
        this.$Axios({ url: 'profile', method: 'get' }).then((resp) => { // 请求成功
          if (resp.return_code === '0000') {
            this.user_info = resp.data.user_info
          }
          resolve(resp)
        }).catch((error) => { // 请求失败
          this.$_requestInterceptor('error', error)
          reject(error)
        })
      })
    },
    getList () {
      var page = this.page
      return new Promise((resolve, reject) => {
        this.$Axios({ url: 'index_activity', params: { page: page, page_size: 10, category_type: 'new' }, method: 'get' }).then((resp) => { // 请求成功
          if (resp.return_code === '0000') {
            this.prd_list = this.prd_list.concat(resp.data.data)
            this.backgroundimage = resp.data.banner_url
            this.backgroundcolor = resp.data.background_color
            if (resp.data.data.length < 10) {
              this.finished = true
            }
          }
          this.loading = false
          resolve(resp)
        }).catch((error) => { // 请求失败
          this.$_requestInterceptor('error', error)
          reject(error)
        })
      })
    }
  }
}
</script>
